package main

import "fmt"

func main() {
	n := 7
	fmt.Println(getMaximumGenerated(n))
}

//link: https://leetcode-cn.com/problems/get-maximum-in-generated-array/
func getMaximumGenerated(n int) (ans int) {
	if n == 0 {
		return 0
	} else if n == 1 {
		return 1
	} else {
		//偶数等于 nums[i/2],奇数等于 nums[i/2]+nums[i/2+1]
		//num0,num1:=0,1
		nums := make([]int, n+1)
		nums[0], nums[1] = 0, 1
		for i := 2; i <= n; i++ {
			if i%2 == 0 {
				nums[i] = nums[i/2]
			} else {
				nums[i] = nums[i/2] + nums[i/2+1]
			}
			ans = max(nums[i], ans)
		}
		return ans
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
